package xin.yangshuai.basic01.gof23.builder;

public class MySQLDatabaseSqlBuilder implements DatabaseSqlBuilder {

    /**
     * 数据库类型
     */
    private String database;

    /**
     * 表名
     */
    private String tableName;

    /**
     * 每页条数
     */
    private Integer pageSize;

    /**
     * 偏移量
     */
    private Integer offset;

    /**
     * sql
     */
    private String sql;

    @Override
    public DatabaseSqlBuilder database() {
        this.database = "MySQL";
        return this;
    }

    public DatabaseSqlBuilder tableName(String tableName) {
        this.tableName = tableName;
        return this;
    }

    public DatabaseSqlBuilder pageSize(Integer pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public DatabaseSqlBuilder offset(Integer offset) {
        this.offset = offset;
        return this;
    }

    @Override
    public DatabaseSqlBuilder sql() {
        this.sql = "select * from " + tableName + " limit " + offset + "," + pageSize + ";";
        return this;
    }

    @Override
    public DatabaseSql build() {
        return new DatabaseSql(database, tableName, pageSize, offset, sql);
    }
}
